package src.threadlocal;

public class ThreadLocalNPE {
    ThreadLocal<Long> longThreadLocal = new ThreadLocal<Long>();

    public void set() {
        longThreadLocal.set(Thread.currentThread().getId());
    }
    public Long get() {
        return longThreadLocal.get();
    }

    public static void main(String[] args) {
        ThreadLocalNPE threadLocalNPE = new ThreadLocalNPE();
        System.out.println("Main Thread: " + threadLocalNPE.get());
        // 线程1
        new Thread(() -> {
            threadLocalNPE.set();
            System.out.println("Thread 1: " + threadLocalNPE.get());
        }).start();

        // 线程2
        new Thread(() -> {
            threadLocalNPE.set();
            System.out.println("Thread 2: " + threadLocalNPE.get());
        }).start();

        // 线程3
        new Thread(() -> {
            System.out.println("Thread 3: " + threadLocalNPE.get());
        }).start();
    }
}
